<!--
 * @Author: your name
 * @Date: 2021-09-28 02:31:52
 * @LastEditTime: 2021-11-01 16:31:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /AutoTestPlant_FrontEnd/src/components/Home.vue
-->

<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/logo2.png" alt="" />
        <span>自动化测试平台</span>
      </div>
      <el-button type="ingo" @click="loginout">退出</el-button>
    </el-header>

    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <!-- 侧边栏区域 -->
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#409BFF" :router="true" :default-active="activePath">
          <!-- 一级菜单 -->
          <el-submenu :index="item.primary_directory_id + ''" v-for="item in menulist" :key="item.primary_directory_id">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconsObj[item.primary_directory_id]" ></i>
              <!-- 文本 -->
              <span>{{item.primary_directory_name}}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item :index="subItem.secondary_directory_path" v-for="subItem in item.children" :key="subItem.secondary_directory_id" 
            @click="saveNavState(subItem.secondary_directory_path)">
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{subItem.secondary_directory_name}}</span>
              </template>
            </el-menu-item>

     

          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
    

<script>
export default {
  data() {
    return {
      // 左侧菜单数据
      menulist:[],
      iconsObj:{
        '1':'el-icon-setting',
        '2':'el-icon-s-operation',
        '3':'el-icon-s-operation',
        '4':'el-icon-s-operation',
        '5':'el-icon-s-operation',
        '6':'el-icon-s-operation',
        '7':'el-icon-pie-chart',
      },
      // 被激活的链接地址
      activePath:'',

    }
  },
  created() {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    // 退出登录
    loginout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 获取所有菜单
    async getMenuList(){
    const {data : res } = await this.$http.get('auth_app/menus/')
    if(res.meta.status !==200) return this.$message.error(res.meta.msg);
    this.menulist = res.data
    console.log(res)
    },
    // 保存激活链接状态
    saveNavState(activePath){
      window,sessionStorage.setItem('activePath',activePath)
      this.activePath = activePath
    }
  },
}
</script>



<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #b3c0d1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #333;
  font-size: 20px;
  // text-align: center;
  line-height: 60px;
  > div {
    display: flex;
    align-items: center;
    > span {
      margin-left: 15px;
    }
  }
  > div img {
    height: 60px;
    width: auto;
  }
}

.el-aside {
  background-color: #d3dce6;
  // color: #333;
  // text-align: center;
  // line-height: 200px;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  // line-height: 160px;
}


</style>